var builMQALink = function(record) {

    var status = record.status;
    var pk_sool_question = record.pk_sool_question;
    var pk_answer_user = record.pk_answer_sool_user;

    if (status == WebSite.askerWaitToAnswerStatus) { //提问者待解答
        return WebSite.AskerUnansweredPage.url+"&pk_question="+pk_sool_question;
    } else if (status == WebSite.askerWaitToHandle) { //提问者待处理
        return WebSite.AskerHandlingPage.url+"&pk_question="+pk_sool_question+"&pk_answer_user="+pk_answer_user;
    } else { //提问者已解决
        return WebSite.AskerSolvedPage.url+"&pk_question="+pk_sool_question;
    }
}

/*点击我的问题跳转到三级页面*/
/*var clickMyQuestion = function(){
    var status = $(this).attr("status");
    var pk_sool_question = $(this).attr("pk_question");
    if (status == WebSite.askerWaitToAnswerStatus) { //提问者待解答
        window.location.href = WebSite.AskerUnansweredPage.url+"&pk_question="+pk_sool_question;
    } else if (status == WebSite.askerWaitToHandle) { //提问者待处理
        window.location.href = WebSite.AskerHandlingPage.url+"&pk_question="+pk_sool_question;
    } else { //提问者已解决
        window.location.href = WebSite.AskerSolvedPage.url+"&pk_question="+pk_sool_question;
    }
};*/

/*我的问题的展现列表*/
var getMyQuestionList = function(){
    WebSite.debug("我的问题的地址"+WebSite.IndexPage.myQuestion_list);
    $.ajax({
        url : WebSite.IndexPage.myQuestion_list,
        type : "post",
        data : {"count":7},
        dataType : "json",
        success : function(result){
            if(result.success) {
                var myQuestion_data = result.resultData;
                for (var i = 0, len = myQuestion_data.length; i < len; i++) {
                    var record = myQuestion_data[i];
                    record.mq_link = builMQALink(record);
                }
                if (myQuestion_data.length > 0) {
                    var myTemplate = Handlebars.compile($("#myQuestion_template").html());
                    $("#myQuestionList").html(myTemplate(myQuestion_data));
                }else{
                    var myTemplate = Handlebars.compile($("#myQuestion_template_img").html());
                    $("#myQuestionList").html(myTemplate(myQuestion_data));
                }
            }
        },
        error : function(){
            alert("没有获得数据");
        }
    });
};

/*展示知道的图片*/
var showKnowPicture = function(){
    $.ajax({
     url : WebSite.IndexPage.showKnowPicture,
     type : "post",
     dataType : "json",
     success : function(result){
         if(result.success){
             var showKnowPicture_data = result.resultData;
             /*点击待解答*/
             showKnowPicture_data.WQS_link = WebSite.MyQuestionListPage.url+"#s1";

             /*点击待处理*/
             showKnowPicture_data.WTHQS_link = WebSite.MyQuestionListPage.url+"#s2";

             /*点击已解决*/
             showKnowPicture_data.SQ_link = WebSite.MyQuestionListPage.url+"#s3";

             /*点击我的提问*/
             showKnowPicture_data.MCQ_link = WebSite.MyQuestionListPage.url;

             /*点击我的回答*/
             showKnowPicture_data.MAQ_link = WebSite.MyAnswerListPage.url;

             /*点击我要提问*/
             showKnowPicture_data.MSUBQ_link = WebSite.CommitPage.url;

             var myTemplate = Handlebars.compile($("#showKnowPicture_template").html());
             $("#showKnowPicture").html(myTemplate(showKnowPicture_data));
         }
     },
     error : function(){
        alert("没有获得数据");
     }
     });
};

/*等你来回答*/
var waitYouToAnswer = function(){
    $.ajax({
        url : WebSite.IndexPage.waitYouToAnswer,
        type : "post",
        data : {"count":7},
        dataType : "json",
        success : function(result){
            if(result.success){
                var waitYouToAnswer_data = result.resultData;
                for (var i = 0, len = waitYouToAnswer_data.length; i < len; i++) {
                    var record = waitYouToAnswer_data[i];
                    var pk_sool_question = record.pk_sool_question;
                    record.wtaq_link = WebSite.ReplyerUnansweredPage.url+"&pk_question="+pk_sool_question;
                }
                var myTemplate = Handlebars.compile($("#waitYouToAnswer_templata").html());
                $("#waitYouToAnswerList").html(myTemplate(waitYouToAnswer_data));
            }
        },
        error : function(){
            alert("没有获得数据");
        }
    });
};

/*排行榜的显示*/
var record = function(){
    $.ajax({
        url : WebSite.IndexPage.record,
        type : "post",
        data : {"count" : 9},
        dataType : "json",
        success : function(result){
            if(result.success){
                var record_data = result.resultData;
                //注册索引+1的helper
                 var handleHelper = Handlebars.registerHelper("addOne",function(index){
                 //利用+1的时机，在父级循环对象中添加一个_index属性，用来保存父级每次循环的索引
                 this._index = index+1;
                 //返回+1之后的结果
                 return this._index;
                 });
                var myTemplate = Handlebars.compile($("#record_template").html());
                $("#recordList").html(myTemplate(record_data));
            }
        },
        error : function(){
            alert("没有获得数据");
        }
    });
};

/*精华问题的显示*/
var essenceQuestion = function(){
    $.ajax({
        url : WebSite.IndexPage.essenceQuestion,
        type : "post",
        data : {"count":2},
        dataType : "json",
        success : function(result){
            if(result.success){
                var essenceQuestion_data = result.resultData;
                for (var i = 0, len = essenceQuestion_data.length; i < len; i++) {
                    var record = essenceQuestion_data[i];
                    var pk_sool_question = record.pk_sool_question;
                    record.EQ_link = WebSite.AskerSolvedPage.url+"&pk_question="+pk_sool_question;
                }
                var myTemplate = Handlebars.compile($("#essenceQuestion_template").html());
                $("#essenceQuestionList").html(myTemplate(essenceQuestion_data));
            }
        },
        error : function(){
            alert("没有获得数据");
        }
    });
};





/*点击我的问题的跟多*/
$("#myQuestionmore").attr("href",WebSite.MyQuestionListPage.url);

/*点击等你来回答问题的跟多*/
$("#waitYouToanswermore").attr("href",WebSite.AllQuestionPage.url);

/*点击精华问题的跟多*/
$("#essencemore").attr("href",WebSite.EssenceQuestionPage.url);

/*我的问题的三种状态的展现*/
var registerHelper = function(){
    Handlebars.registerHelper("compare",function(v1,options){
       if(v1 == 1){
           return options.fn(this);
       } else{
           return options.inverse(this);
       }
    });
}

var registerHelper_status = function(){
    Handlebars.registerHelper("compare_status",function(v1,options){
        if(v1 == 2){
            return options.fn(this);
        } else{
            return options.inverse(this);
        }
    });
}

/*排行榜的增强if循环*/
var registerHelper_status1 = function(){
    Handlebars.registerHelper("record_status1",function(v1,options){
        var v2 = v1 + 1;
        if(v2 == 1){
            return options.fn(this);
        } else{
            return options.inverse(this);
        }
    });
}
var registerHelper_status2 = function(){
    Handlebars.registerHelper("record_status2",function(v1,options){
        var v2 = v1 + 1;
        if(v2 == 2){
            return options.fn(this);
        } else{
            return options.inverse(this);
        }
    });
}
var registerHelper_status3 = function(){
    Handlebars.registerHelper("record_status3",function(v1,options){
        var v2 = v1 + 1;
        if(v2 == 3){
            return options.fn(this);
        } else{
            return options.inverse(this);
        }
    });
}
var registerHelper_status4 = function(){
    Handlebars.registerHelper("record_status4",function(v1,options){
        var v2 = v1 + 1;
        if(v2 == 4 || v2 == 5){
            return options.fn(this);
        } else{
            return options.inverse(this);
        }
    });
}










